package com.jianyun.jyzs.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.activity.CrmGetFunnelActivity;
import com.jianyun.jyzs.bean.CrmFunnelList;

import java.util.List;

/**
 * Created by mlli on 2017/8/23.
 */

public class RightStateAdapter extends BaseAdapter {

    private CrmGetFunnelActivity act;
    private List<CrmFunnelList.FunnelBean> data;

    public RightStateAdapter(CrmGetFunnelActivity act, List<CrmFunnelList.FunnelBean> data) {
        super();
        this.act = act;
        this.data = data;
    }

    public void setData(List<CrmFunnelList.FunnelBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data==null?0:data.size();
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        UserViewHolder mHolder = null;
        if(convertView == null) {
            convertView = View.inflate(act, R.layout.item_crm_search_part_right_state, null);
            mHolder = new UserViewHolder();
            mHolder.headName = (TextView) convertView.findViewById(R.id.headName);
            mHolder.area = (LinearLayout) convertView.findViewById(R.id.area);
            convertView.setTag(mHolder);
        } else {
            // 取出holder类
            mHolder = (UserViewHolder) convertView.getTag();
        }
        try {
            final CrmFunnelList.FunnelBean bean = data.get(position);
            mHolder.headName.setText(bean.getName());
            mHolder.area.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    act.setFunnel(bean.getName());
                }
            });
        }catch (Exception e){
            e.printStackTrace();
        }

        return convertView;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    class UserViewHolder {
        public TextView headName;
        public LinearLayout area;
    }
}
